
//
// 120206 - AH - (Bien) Created.
//

package org.soekrat.gui.swing.motor.passingstrategy;

import java.util.Hashtable;

import org.soekrat.engine.motor.passingstrategies.PassingStrategy;
import org.soekrat.engine.wheel.ontology.ForestOntology;
import org.soekrat.engine.wheel.ontology.MineOntology;
import org.soekrat.engine.wheel.ontology.NetworkOntology;
import org.soekrat.engine.wheel.ontology.Ontology;
import org.soekrat.engine.wheel.ontology.ProductTableOntology;

/**
 * <p>
 *   Utility methods of use when working with
 *   {@link PassingStrategy} objects at GUI level.
 * </p>
 * @author Laetitia Le Chatton (LLC) 
 * @author Arne Halvorsen (AH) 
 */
public final class PassingStrategyUtil 
{
  private PassingStrategyUtil(){}
  
  //
  // Stuff the Suite will take over.
  // 

  /**
   * <p>
   *   Gets qualified name on
   *   {@link Ontology} class given it's name displayed to end user. 
   * </p>
   * @param uname End user name of ontology.
   * @return Qualified class name of ontology or {@code null} if not found.
   */
  public static String getOntologyClassNameForUname(String uname)
  {
    uname=(uname==null) ? "" : uname.trim();
    uname=uname.toLowerCase();
    Class<?> clazz=c_ontologiesByUname.get(uname);
    return clazz==null ? null : clazz.getName();
  }
  
  /**
   * <p>
   *   Gets name on ontology to show to end user given ontology's qualified
   *   class name.
   * </p>
   * @param cname Qualified class name.
   * @return End user name or {@code null} if not found.
   */
  public static String getOntologyClassForCname(String cname)
  {
    cname=(cname==null) ? "" : cname.trim();
    return c_ontologiesByCname.get(cname);
  }
  
  private static final Hashtable<String, Class<?>> c_ontologiesByUname=
    new Hashtable<String, Class<?>>();
  
  private static final Hashtable<String, String> c_ontologiesByCname=
    new Hashtable<String, String>();
  
  private static void registerOntology(String uname, Class<?> clazz)
  {
    c_ontologiesByUname.put(uname, clazz);
    c_ontologiesByCname.put(clazz.getName(), uname);
  }
  
  static
  {
    registerOntology("mine", MineOntology.class);
    registerOntology("network", NetworkOntology.class);
    registerOntology("forest", ForestOntology.class);
    registerOntology("product table", ProductTableOntology.class);
  }
  
}
